import request from '@/utils/request'

export function getCustomerBuyPhone(phone) {
  return request({
    url: 'api/get-customer?phone=' + phone,
    method: 'get'
  })
}

export function getAppUserByPhone(data) {
  return request({
    url: 'api/get-app-user-by-phone?phone_list=' + data,
    method: 'get'
  })
}

export function updateAppUserMemberType(data) {
  return request({
    url: 'api/update-app-user-member-type',
    method: 'post',
    data
  })
}

export function add(data) {
  return request({
    url: 'api/users',
    method: 'post',
    data
  })
}

export function updateUserPhone(phone) {
  return request({
    url: 'api/users/updatePhone/' + phone,
    method: 'post'
  })
}

export function del(id) {
  return request({
    url: 'api/users/' + id,
    method: 'delete'
  })
}

export function edit(data) {
  return request({
    url: 'api/users',
    method: 'put',
    data
  })
}

export function updatePass(password) {
  const data = {
    password
  }
  return request({
    url: 'api/users/updatePass/',
    method: 'post',
    data
  })
}

export function updateEmail(code, data) {
  return request({
    url: 'api/users/updateEmail/' + code,
    method: 'post',
    data
  })
}

export function getRoleList(userId) {
  return request({
    url: 'api/testPermissions',
    method: 'get',
    params: {
      userId
    }
  })
}

export function downloadUser() {
  return request({
    url: 'api/users/download',
    method: 'get',
    responseType: 'blob'
  })
}

export function getUserByPhone(data) {
  return request({
    url: 'api/users?phone=' + data,
    method: 'get',
    data
  })
}

// 新增用户到单点登陆系统中
export function addLoginUser(data) {
  return request({
    url: process.env.LOGIN_API + '/weiqiao/adduser',
    method: 'post',
    data
  })
}

// 修改用户信息
export function updateLoginUser(data) {
  return request({
    url: process.env.LOGIN_API + '/weiqiao/update-user',
    method: 'post',
    data
  })
}

// 获取当前用户所在的所有公司id
export function getCurrentCompanyId() {
  return request({
    url: 'api/currentCompanyId',
    method: 'get'
  })
}

// 根据公司id获取公司信息
export function getCompanyByCompanyId(companyId) {
  return request({
    url: process.env.LOGIN_API + '/weiqiao/company',
    method: 'get',
    params: { companyid: companyId }
  })
}

// 发送验证码
export function sendCode(telephone) {
  return request({
    url: process.env.WEICHAOYUN + '/ms/sendCode.do',
    method: 'get',
    params: { telephone: telephone }
  })
}

// 注册公司
export function addConsumer(form) {
  return request({
    url: process.env.WEICHAOYUN + '/ms/addConsumer.do',
    method: 'get',
    params: { ...form }
  })
}

// 切换公司时根据公司id数组获取所有公司信息
export function getCompanysByIds(companyIds) {
  return request({
    url: process.env.LOGIN_API + '/weiqiao/companies',
    method: 'get',
    params: {
      companyids: companyIds + ''
    }
  })
}

// 调用切换公司接口 获取新的token
export function cutCompany(token, companycode) {
  return request({
    url: process.env.LOGIN_API + '/weiqiao/changecompany',
    method: 'get',
    params: {
      token: token,
      companycode: companycode
    }
  })
}
